//
//  M1HomeDetailsVC.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/16.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1HomeDetailsVC.h"
#import "M1HomeDetailsHeaderView.h"
#import "M1HomeVipCell.h"
#import "M1HerCircleofFriendsCell.h"
#import "M1IntroduceMyselfCell.h"
#import "M1HomeDetailsListCell.h"
#import "M1AnonymousReportVC.h"
#import "M1HomeModel.h"
#import "M1HomeDetailsListVC.h"
#import "M1PersonalDataVC.h"
#import "M1PhotoGalleryVC.h"
#import "M1LikePairingVC.h"

@interface M1HomeDetailsVC ()

@property (nonatomic, assign) NSInteger likeNum;

@property (nonatomic, strong) UIView *m1_navigationBarBackgroundView;

@property (nonatomic, strong) UIView *m1_basicsView;

@property (nonatomic, strong) UIView *m1_mateView;

@property (nonatomic, strong) M1HomeDetailsHeaderView *m1_headerView;

@property (nonatomic, strong) M1HomeModel *m1_detailsModel;

@property (nonatomic, strong) UIView *m1_toolBar;

@property (nonatomic, assign) BOOL m1_unIntroduce;

@property (nonatomic, strong) UIButton *m1_likeBtn;

@property (nonatomic, strong) UIButton *m1_superBtn;

@property (nonatomic, strong) UIButton *m1_chatBtn;

@end

@implementation M1HomeDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.m1_hiddenNav = YES;
    
    self.m1_listData = [NSMutableArray arrayWithCapacity:0];
    
    [self.m1_tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    self.m1_headerView = [[M1HomeDetailsHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENWIDTH + 130)];
    
    self.m1_headerView.m1_viewController = self;
    
    self.m1_tableView.tableHeaderView = _m1_headerView;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 119)];
    self.m1_tableView.tableFooterView = view;
    
    [self.m1_tableView registerNib:[UINib nibWithNibName:@"M1HomeVipCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"M1HomeVipCellIdentifier"];

    [self.m1_tableView registerClass:[M1IntroduceMyselfCell class] forCellReuseIdentifier:@"M1IntroduceMyselfCellIdentifier"];

    [self.m1_tableView registerClass:[M1HomeDetailsListCell class] forCellReuseIdentifier:@"M1HomeDetailsListCellOneIdentifier"];

    
    [self m1_createToolbar];
    
    [self m1_createNav];
    
    [self m1_requestData];
}

- (void)m1_leftAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)m1_rightAction{
    M1SheetView *m1_sheet = [[M1SheetView alloc]initWithTitles:@[@"匿名举报",@"不在看Ta"]];
    [m1_sheet m1_show];
    
    WEAKSELF
    m1_sheet.click = ^(NSInteger index) {
        if (![M1User user]) {
            WEAKSELF
            [M1Alert m1_alertWithTitle:nil message:m1_loginText buttonTitles:@[@"取消", @"登录"] action:^(NSInteger index) {
                if (index == 1) {
                    M1LoginVC *loginVC = [[M1LoginVC alloc] init];
                    loginVC.m1_changeNavTitleColor = YES;
                    loginVC.m1_changeBackImage = YES;
                    loginVC.hidesBottomBarWhenPushed = YES;
                    [weakSelf.navigationController pushViewController:loginVC animated:YES];
                }
            }];
            return;
        }
        if (index == 0) {
            M1AnonymousReportVC *anonyVC = [[M1AnonymousReportVC alloc] init];
            anonyVC.uid = weakSelf.m1_detailsModel.basic.uid;
            [self.navigationController pushViewController:anonyVC animated:YES];
        }else if (index == 1){
            [M1HttpNet requestWithMethod:m1_join_blacklist_url params:@{@"to_uid": weakSelf.m1_detailsModel.basic.uid} success:^(id resDic, NSInteger code, NSString *message) {
                [M1Alert m1_alertWithTitle:nil message:message];
            } fail:^(id resDic, NSInteger code, NSString *message) {
                [M1Alert m1_alertWithTitle:nil message:message];
            } showAni:YES];
        }
    };
}



- (void)m1_allAction:(UIButton *)sender{
    if (![M1User user]) {
        WEAKSELF
        [M1Alert m1_alertWithTitle:nil message:m1_loginText buttonTitles:@[@"取消", @"登录"] action:^(NSInteger index) {
            if (index == 1) {
                M1LoginVC *loginVC = [[M1LoginVC alloc] init];
                loginVC.m1_changeNavTitleColor = YES;
                loginVC.m1_changeBackImage = YES;
                loginVC.hidesBottomBarWhenPushed = YES;
                [weakSelf.navigationController pushViewController:loginVC animated:YES];
            }
        }];
        return;
    }
    
    if (sender.tag == 1) {
        M1HomeDetailsListVC *listVC = [[M1HomeDetailsListVC alloc] init];
        listVC.m1_model = self.m1_detailsModel;
        [self.navigationController pushViewController:listVC animated:YES];
    }else{
        
    }
}

#pragma mark - LikeAction
- (void)m1_buttonAction:(UIButton *)sender{
    WEAKSELF
    if (![M1User user]) {
        [M1Alert m1_alertWithTitle:nil message:m1_loginText buttonTitles:@[@"取消", @"登录"] action:^(NSInteger index) {
            if (index == 1) {
                M1LoginVC *loginVC = [[M1LoginVC alloc] init];
                loginVC.m1_changeNavTitleColor = YES;
                loginVC.m1_changeBackImage = YES;
                loginVC.hidesBottomBarWhenPushed = YES;
                [weakSelf.navigationController pushViewController:loginVC animated:YES];
            }
        }];
        return;
    }
    
    if (sender.tag == 1) {
        if ([self.m1_likeBtn.imageView.image isEqual:LOAD_LOCAL_IMG(@"details_icon_like_sel")]) {
            [M1HttpNet requestWithMethod:m1_user_unlike_url params:@{@"to_uid":self.m1_model.basic.uid} success:^(id resDic, NSInteger code, NSString *message) {
                weakSelf.likeNum --;
                [M1Alert m1_alertWithTitle:nil message:@"取消喜欢成功"];
                [weakSelf.m1_likeBtn setImage:LOAD_LOCAL_IMG(@"details_icon_like") forState:UIControlStateNormal];
                [weakSelf.m1_headerView.m1_likeBtn setTitle:[NSString stringWithFormat:@"%ld", weakSelf.likeNum] forState:UIControlStateNormal];
            } fail:^(id resDic, NSInteger code, NSString *message) {
                
            } showAni:YES];
        }else{
            [M1HttpNet requestWithMethod:m1_user_like_url params:@{@"to_uid":self.m1_model.basic.uid} success:^(id resDic, NSInteger code, NSString *message) {
                weakSelf.likeNum ++;
                [M1Alert m1_alertWithTitle:nil message:@"喜欢成功"];
                [weakSelf.m1_likeBtn setImage:LOAD_LOCAL_IMG(@"details_icon_like_sel") forState:UIControlStateNormal];
                [weakSelf.m1_headerView.m1_likeBtn setTitle:[NSString stringWithFormat:@"%ld", weakSelf.likeNum] forState:UIControlStateNormal];

            } fail:^(id resDic, NSInteger code, NSString *message) {
                if (code == -20001 || code == -20003 ||code == -20002) {
                    [M1Alert m1_alertWithTitle:nil message:message buttonTitles:@[@"取消", @"立即完善"] action:^(NSInteger index) {
                        if (index == 1) {
                            if ([[M1User user].basic.avatar.img.url length] <= 0) {
                                M1PhotoGalleryVC *photoVC = [[M1PhotoGalleryVC alloc] init];
                                photoVC.hidesBottomBarWhenPushed = YES;
                                [weakSelf.navigationController pushViewController:photoVC animated:YES];
                            }else{
                                M1PersonalDataVC *dataVC = [[M1PersonalDataVC alloc] init];
                                dataVC.hidesBottomBarWhenPushed = YES;
                                [weakSelf.navigationController pushViewController:dataVC animated:YES];
                            }
                        }
                    }];
                }else if (code <= -10000 && code >= -20000){
                    [M1Alert m1_alertWithTitle:nil message:message buttonTitles:@[@"取消", @"前往"] action:^(NSInteger index) {
                        [weakSelf m1_goVipVC];
                    }];
                }else if (code == -20004){
                    weakSelf.likeNum ++;
                    [weakSelf.m1_likeBtn setImage:LOAD_LOCAL_IMG(@"details_icon_like_sel") forState:UIControlStateNormal];
                    [weakSelf.m1_headerView.m1_likeBtn setTitle:[NSString stringWithFormat:@"%ld", weakSelf.likeNum] forState:UIControlStateNormal];
                    
                    M1LikePairingVC *pairingVC = [[M1LikePairingVC alloc] init];
                    pairingVC.m1_model = weakSelf.m1_detailsModel;
                    [weakSelf.navigationController pushViewController:pairingVC animated:YES];
                }else{
                    [M1Alert m1_alertWithTitle:nil message:message];
                }
            } showAni:YES];
        }
    }else if (sender.tag == 2){
       
        if ([self.m1_superBtn.imageView.image isEqual:LOAD_LOCAL_IMG(@"details_icon_superLike")]) {
            [M1HttpNet requestWithMethod:m1_super_like_url params:@{@"to_uid":self.m1_model.basic.uid} success:^(id resDic, NSInteger code, NSString *message) {
                [M1Alert m1_alertWithTitle:nil message:@"已成功表达心意"];
                [weakSelf.m1_superBtn setImage:LOAD_LOCAL_IMG(@"home_icon_superLike") forState:UIControlStateNormal];
                if (weakSelf.m1_superLikeBlock) {
                    weakSelf.m1_superLikeBlock();
                }
            } fail:^(id resDic, NSInteger code, NSString *message) {
                if (code == -20001 || code == -20002 || code == -20003) {
                    [M1Alert m1_alertWithTitle:@"" message:message buttonTitles:@[@"取消", @"立即完善"] action:^(NSInteger index) {
                        if (index == 1) {
                            if ([[M1User user].basic.avatar.img.url length] <= 0||[M1User user].basic.photos.count == 0) {
                                M1PhotoGalleryVC *photoVC = [[M1PhotoGalleryVC alloc] init];
                                photoVC.hidesBottomBarWhenPushed = YES;
                                [weakSelf.navigationController pushViewController:photoVC animated:YES];
                            }else{
                                M1PersonalDataVC *dataVC = [[M1PersonalDataVC alloc] init];
                                dataVC.hidesBottomBarWhenPushed = YES;
                                [weakSelf.navigationController pushViewController:dataVC animated:YES];
                            }
                        }
                    }];
                }else if (code <= -10000 && code>=-20000){
                    [M1Alert m1_alertWithTitle:nil message:message buttonTitles:@[@"取消", @"前往"] action:^(NSInteger index) {
                        if (index == 1) {
                            [weakSelf m1_goVipVC];
                        }
                    }];
                }else if (code == -20015){
                    [weakSelf.m1_superBtn setImage:LOAD_LOCAL_IMG(@"home_icon_superLike") forState:UIControlStateNormal];
                    M1LikePairingVC *pairingVC = [[M1LikePairingVC alloc] init];
                    pairingVC.m1_model = weakSelf.m1_detailsModel;
                    pairingVC.hidesBottomBarWhenPushed = YES;
                    [weakSelf.navigationController pushViewController:pairingVC animated:YES];
                    if (weakSelf.m1_superLikeBlock) {
                        weakSelf.m1_superLikeBlock();
                    }
                }else{
                    [M1Alert m1_alertWithTitle:nil message:message];
                }
            } showAni:YES];
        }else{
            [M1Alert m1_alertWithTitle:nil message:@"已经表达了心意"];
        }
    }else{
        [weakSelf m1_toChat];
    }
}
-(void)m1_toChat{
    NSArray *array = self.navigationController.viewControllers;
    if ([array[array.count - 2] isKindOfClass:[M1MessageViewController class]]) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    WEAKSELF;
    [M1User m1_userPermissionForm:self type:M1UserPermission_Chat to_uid:self.m1_detailsModel.basic.uid permission:^(NSDictionary *resDic) {
        [[EaseDataBase sharedDataBase] addMessage:[self.m1_detailsModel.basic.uid m1_MD5] uid:self.m1_detailsModel.basic.uid name:self.m1_detailsModel.basic.name avatar:self.m1_detailsModel.basic.avatar.img.url];
        M1MessageViewController *m1_messageVC = [[M1MessageViewController alloc] initWithConversationChatter:[self.m1_detailsModel.basic.uid m1_MD5] conversationType:EMConversationTypeChat];
        m1_messageVC.m1_uid = self.m1_detailsModel.basic.uid;
        m1_messageVC.title = self.m1_detailsModel.basic.name;
        [weakSelf.navigationController pushViewController:m1_messageVC animated:YES];
    }];
}
- (void)m1_requestData{
    WEAKSELF
    [M1HttpNet requestWithMethod:m1_user_info_url params:@{@"uid":self.m1_model.basic.uid} success:^(id resDic, NSInteger code, NSString *message) {
        weakSelf.m1_detailsModel = [M1HomeModel mj_objectWithKeyValues:resDic];

        [weakSelf.m1_headerView m1_setModel:weakSelf.m1_detailsModel];
        
        weakSelf.likeNum = [weakSelf.m1_detailsModel.status.liked_count integerValue];
        
        if (weakSelf.m1_detailsModel.status.liked == 1) {
            [weakSelf.m1_likeBtn setImage:LOAD_LOCAL_IMG(@"details_icon_like_sel") forState:UIControlStateNormal];
        }else{
            [weakSelf.m1_likeBtn setImage:LOAD_LOCAL_IMG(@"details_icon_like") forState:UIControlStateNormal];
        }
        
        if (weakSelf.m1_detailsModel.status.is_me_super == 1) {
            [weakSelf.m1_superBtn setImage:LOAD_LOCAL_IMG(@"home_icon_superLike") forState:UIControlStateNormal];
        }else{
            [weakSelf.m1_superBtn setImage:LOAD_LOCAL_IMG(@"details_icon_superLike") forState:UIControlStateNormal];

        }
        
        [weakSelf.m1_listData addObjectsFromArray:@[self.m1_detailsModel.basic.abode, self.m1_detailsModel.basic.job, self.m1_detailsModel.basic.high, self.m1_detailsModel.basic.annual_income]];
        
        [weakSelf.m1_tableView reloadData];
    } fail:^(id resDic, NSInteger code, NSString *message) {
        
    } showAni:YES];
    
    
}


-(void)m1_goVipVC{
    WEAKSELF;
    M1VIPCenterVC *vipVC = [[M1VIPCenterVC alloc] init];
    [self.navigationController pushViewController:vipVC animated:YES];
    vipVC.buyVip = ^(BOOL isSuccess) {
        [weakSelf.m1_tableView reloadData];
    };
}

#pragma mark - tableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && [M1User user].status.member_fees_status != 1) {
        if (![M1User user]) {
            WEAKSELF
            [M1Alert m1_alertWithTitle:nil message:m1_loginText buttonTitles:@[@"取消", @"登录"] action:^(NSInteger index) {
                if (index == 1) {
                    M1LoginVC *loginVC = [[M1LoginVC alloc] init];
                    loginVC.m1_changeNavTitleColor = YES;
                    loginVC.m1_changeBackImage = YES;
                    loginVC.hidesBottomBarWhenPushed = YES;
                    [weakSelf.navigationController pushViewController:loginVC animated:YES];
                }
            }];
            return;
        }
        
        [self m1_goVipVC];
        
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSInteger number = 2;
    
    if ([M1User user].status.member_fees_status != 1) {
        number = 3;
    }
    
    return number;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger numberOfRows = 1;
    
    if ([M1User user].status.member_fees_status != 1) {
        if (section == 2) {
            numberOfRows = 4;
        }
    }else{
        if (section == 1) {
            numberOfRows = 4;
        }
    }
    
    return numberOfRows;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    CGFloat heightForHeder = 0.01;
    if ([M1User user].status.member_fees_status != 1) {
        if (section == 1 || section == 2) {
            heightForHeder = 45;
        }
    }else{
        if (section == 0 || section == 1) {
            heightForHeder = 45;
        }
    }
    return heightForHeder;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *viewForHeader = nil;
    
    if ([M1User user].status.member_fees_status != 1) {
        if (section == 1 || section == 2) {
            viewForHeader = [self m1_viewForHeader:@[@"自我介绍", @"基本资料"][section - 1]];
        }
    }else{
        if (section == 0 || section == 1) {
            viewForHeader = [self m1_viewForHeader:@[@"自我介绍", @"基本资料"][section]];
        }
    }
    
    
    return viewForHeader;
}

- (UIView *)m1_viewForHeader:(NSString *)title{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 45)];
    
    bgView.backgroundColor = m1_color(0xF7F9FB);
    
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.text = title;
    titleLbl.textColor = m1_color(0x999999);
    titleLbl.font = m1_font(15);
    [bgView addSubview:titleLbl];
    
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.centerY.mas_equalTo(bgView.mas_centerY);
    }];
    
    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    CGFloat heightForFooter = 0.01;
    if ([M1User user].status.member_fees_status != 1) {
        if (section == 2) {
            heightForFooter = 40;
        }
    }else{
        if (section == 1) {
            heightForFooter = 40;
        }
    }
    
    return heightForFooter;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *viewForFooter = nil;
    if ([M1User user].status.member_fees_status != 1) {
        if (section == 2) {
            viewForFooter = self.m1_basicsView;
        }
    }else{
        if (section == 1) {
            viewForFooter = self.m1_basicsView;
        }
    }
    
//    else if (section == 3){
//        viewForFooter = self.m1_mateView;
//    }
    
    return viewForFooter;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([M1User user].status.member_fees_status != 1) {
        if (indexPath.section == 0) {
            M1HomeVipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"M1HomeVipCellIdentifier"];


            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            return cell;
        }else if (indexPath.section == 1){
            M1IntroduceMyselfCell *cell = [tableView dequeueReusableCellWithIdentifier:@"M1IntroduceMyselfCellIdentifier"];

            cell.m1_title.text = self.m1_detailsModel.basic.about_me;

            [cell m1_loadText:self.m1_detailsModel.basic.about_me unIntroduce:self.m1_unIntroduce];
            WEAKSELF
            cell.m1_upLoad = ^{
                weakSelf.m1_unIntroduce = !weakSelf.m1_unIntroduce;
                [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            };

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            return cell;
        }
    }else{
        if (indexPath.section == 0){
            M1IntroduceMyselfCell *cell = [tableView dequeueReusableCellWithIdentifier:@"M1IntroduceMyselfCellIdentifier"];
            
            cell.m1_title.text = self.m1_detailsModel.basic.about_me;
            
            [cell m1_loadText:self.m1_detailsModel.basic.about_me unIntroduce:self.m1_unIntroduce];
            WEAKSELF
            cell.m1_upLoad = ^{
                weakSelf.m1_unIntroduce = !weakSelf.m1_unIntroduce;
                [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            };
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
    }
    M1HomeDetailsListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"M1HomeDetailsListCellOneIdentifier"];
    
    cell.m1_title.text = @[@"所在地", @"职业", @"身高", @"年收入"][indexPath.row];
    
    if (self.m1_listData.count > 0) {
        if ([self.m1_listData[indexPath.row] length] <= 0) {
            cell.m1_content.text = @"未填写";
            
        }else{
            if ([cell.m1_title.text isEqualToString:@"身高"] && [self.m1_listData[indexPath.row] length] > 0) {
                cell.m1_content.text = [NSString stringWithFormat:@"%@cm", self.m1_listData[indexPath.row]];
            }else{
                cell.m1_content.text = self.m1_listData[indexPath.row];
            }
        }
    }else{
        cell.m1_content.text = @"未填写";
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.m1_navigationBarBackgroundView.alpha = scrollView.contentOffset.y > SCREENWIDTH - 44 - STATUS_HEIGHT;
    
    self.m1_headerView.m1_offset_y = scrollView.contentOffset.y;
    
    WEAKSELF
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.m1_toolBar.frame = CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 119);
    }];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (!decelerate) {
        WEAKSELF
        [UIView animateWithDuration:0.5 animations:^{
            weakSelf.m1_toolBar.frame = CGRectMake(0, SCREENHEIGHT - 119, SCREENWIDTH, 119);
        }];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    WEAKSELF
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.m1_toolBar.frame = CGRectMake(0, SCREENHEIGHT - 119, SCREENWIDTH, 119);
    }];
}

- (UIView *)m1_basicsView{
    if (!_m1_basicsView) {
        _m1_basicsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 40)];
        _m1_basicsView.backgroundColor = m1_color(0xFFFFFF);
        
        [self m1_createBtn:_m1_basicsView tag:1];
        
    }
    return _m1_basicsView;
}

- (UIView *)m1_mateView{
    if (!_m1_mateView) {
        _m1_mateView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 40)];
        _m1_mateView.backgroundColor = m1_color(0xFFFFFF);
        
        [self m1_createBtn:_m1_mateView tag:2];
        
    }
    return _m1_mateView;
}

- (void) m1_createToolbar{
    self.m1_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENHEIGHT - 119, SCREENWIDTH, 119)];
//    _m1_toolBar.backgroundColor = m1_color(0xF7F9FB);
    _m1_toolBar.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_m1_toolBar];
    
    self.m1_likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _m1_likeBtn.frame = CGRectMake((SCREENWIDTH - 88 * 3) / 4, 16, 88, 88);
    _m1_likeBtn.tag = 1;
    [_m1_likeBtn addTarget:self action:@selector(m1_buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_m1_toolBar addSubview:_m1_likeBtn];
    
    self.m1_superBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _m1_superBtn.frame = CGRectMake((SCREENWIDTH - 88 * 3) / 4 * 2 + 88, 16, 88, 88);
    [_m1_superBtn setImage:LOAD_LOCAL_IMG(@"details_icon_superLike") forState:UIControlStateNormal];
    _m1_superBtn.tag = 2;
    [_m1_superBtn addTarget:self action:@selector(m1_buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_m1_toolBar addSubview:_m1_superBtn];
    
    self.m1_chatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _m1_chatBtn.frame = CGRectMake((SCREENWIDTH - 88 * 3) / 4 * 3 + 88 * 2, 16, 88, 88);
    [_m1_chatBtn setImage:LOAD_LOCAL_IMG(@"details_icon_chat") forState:UIControlStateNormal];
    _m1_chatBtn.tag = 3;
    [_m1_chatBtn addTarget:self action:@selector(m1_buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_m1_toolBar addSubview:_m1_chatBtn];
}

- (void) m1_createBtn:(UIView *)view tag:(NSInteger)tags{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"展开全部" forState:UIControlStateNormal];
    [button setTitleColor:m1_color(0xFF5A3F) forState:UIControlStateNormal];
    button.titleLabel.font = m1_font(14);
    [button setImage:LOAD_LOCAL_IMG(@"details_icon_across") forState:UIControlStateNormal];
    [button sizeToFit];
    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, -button.imageView.frame.size.width - button.frame.size.width + button.titleLabel.frame.size.width - 10, 0, 0)];
    [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -button.titleLabel.frame.size.width - button.frame.size.width + button.imageView.frame.size.width)];
    button.tag = tags;
    [button addTarget:self action:@selector(m1_allAction:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view.mas_centerX).offset(5);
        make.top.bottom.offset(0);
        make.width.offset(80);
    }];
}

- (void) m1_createNav{
    self.m1_navigationBarBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 44 + STATUS_HEIGHT)];
    
    self.m1_navigationBarBackgroundView.backgroundColor = m1_color(0x1f1f1f);
    
    self.m1_navigationBarBackgroundView.hidden = NO;
    
    [self.view addSubview:self.m1_navigationBarBackgroundView];
    
    self.m1_navigationBarBackgroundView.alpha = 0;
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(15, STATUS_HEIGHT + 9, 30, 30);
    [backBtn setImage:LOAD_LOCAL_IMG(@"details_icon_fanhui") forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(m1_leftAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    UIButton *reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    reportBtn.frame = CGRectMake(SCREENWIDTH - 50, STATUS_HEIGHT + 7, 40, 30);
    [reportBtn setImage:LOAD_LOCAL_IMG(@"details_icon_more") forState:UIControlStateNormal];
    [reportBtn addTarget:self action:@selector(m1_rightAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:reportBtn];
}

- (void) m1_createRightBarButtonImage:(NSString *)image action:(SEL)action{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 40, 40);
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightBtn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
